<template>
  <div class="_fillMsg2">
    <div class="formContainer">
      <van-form ref="editForm" @submit="formSubmit">
        <van-field v-model="userName" label="姓名：" placeholder="姓名" />
        <van-field v-model="phone" label="手机号：" placeholder="手机号" />
        <van-field
          class="addBorder"
          v-model="address"
          label="地址："
          placeholder="地址"
          type="textarea"
          autosize
          rows="1"
        />
      </van-form>
    </div>
    <div class="submitBtnCon">
      <van-button class="submitBtn bgPrimary" round @click="formSubmit"
        >提交</van-button
      >
    </div>
  </div>
</template>

<script>
import { mapActions, mapMutations } from "vuex";
import { Popup, Form, Field, Row, Button, Toast, Dialog } from "vant";
import { phoneReg } from "@/js/reg";
import { utf16toEntities, uncodeUtf16, get_time_diff } from "@/js/utils";
import { aid } from "@/config/shareConfig";
export default {
  components: {
    [Popup.name]: Popup,
    [Form.name]: Form,
    [Field.name]: Field,
    [Row.name]: Row,
    [Button.name]: Button,
  },
  data() {
    return {
      //   areaList,
      showArea: false,
      areaValue: "",
      userName: "",
      phone: "",
      address: "",
      goodsId: 0,
      dialogVisible: false,
      awayTime: "",
    };
  },
  methods: {
    ...mapActions({
      addEnroll: "activity/addEnroll",
    }),
    formSubmit() {
      if (!this.userName) {
        return Toast("请输入姓名");
      }
      if (!phoneReg.test(this.phone)) {
        return Toast("请输入正确的手机号");
      }
      if (!this.address) {
        return Toast("请输入地址");
      }
      if (!this.$store.state.userInfo.openId) {
        return Toast("数据尚未初始化");
      }
      this.addEnroll({
        open_id: this.$store.state.userInfo.openId,
        ac_id: aid,
        name: this.userName,
        address: this.address,
        mobile: this.phone,
      })
        .then((res) => {
          console.log(res);
          if (res && res.code == 0) {
            Toast.success("提交成功");
            this.$router.go(-1); 
          } else {
            Toast.fail("出错了~");
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
    saveClick() {
      this.$refs.editForm.submit();
    },
  },
};
</script>

<style lang="scss">
._fillMsg2 {
  height: 100vh;
  background-color: white;
  .van-cell--borderless::after,
  .van-cell:last-child::after {
    display: initial;
  }
  .addBorder {
    &::after {
      position: absolute;
      box-sizing: border-box;
      content: " ";
      pointer-events: none;
      right: 0;
      bottom: 0;
      left: 16px;
      border-bottom: 1px solid #ebedf0;
      -webkit-transform: scaleY(0.5);
      transform: scaleY(0.5);
    }
  }
  .submitBtnCon {
    padding: 12px 24px;

    .submitBtn {
      width: 100%;
      background-color: #ac1a24;
      color: white;
    }
  }
}
</style>